import type { RequestEventStreamOptions } from 'ofetch'

const chatDialogApi = {
    /**
     * 流式对话
     *
     * @param {Object} params
     * @param {number} params.sid 会话窗口ID
     * @param {string} params.bot 智能体编号
     * @param {string} [params.scene] 来源场景
     * @param {boolean} params.stream 流式响应
     * @param {boolean} params.search 联网搜索
     * @param {any[]} params.messages 消息上下文
     * @param {RequestEventStreamOptions} config
     * @param {any} [headers] 请求头信息
     * @returns {Promise<any>}
     * @author zero
     */
    sendChat(params: {
        sid?: number;
        bot?: string;
        scene?: string;
        search?: boolean;
        stream: boolean;
        messages: any[];
    }, config: RequestEventStreamOptions, headers?: any): Promise<any> {
        config.apiPrefix = ''
        return $request.eventStream({
            url: '/v1/chat/completions',
            method: 'POST',
            params,
            headers
        }, config)
    },

    /**
     * 记录列表
     *
     * @param {Object} params
     * @param {string} params.bot 智能体编号
     * @param {number} params.sid 会话窗口ID
     * @param {string} [params.scene] 场景: [normal,test,web,api]
     * @param {any} [headers] 请求头信息
     * @returns {Promise<ChatRecordsListResponse[]>}
     * @author zero
     */
    history(params: {
        bot?: string;
        sid?: number;
        scene?: string;
    }, headers?: any): Promise<ChatRecordsListResponse[]> {
        return $request.get<ChatRecordsListResponse[]>({
            url: '/v1/chat/history',
            params,
            headers
        }, { apiPrefix: '' })
    },

    /**
     * 清空上下文
     *
     * @param {Object} params
     * @param {string} [params.scene] - 场景值
     * @param {string} [params.bot] - 智能体编号
     * @param {number} [params.sid] - 会话窗口ID
     * @param {any} [headers] - 请求头信息
     * @returns {Promise<void>}
     * @author zero
     */
    clear(params: {
        scene?: string;
        bot?: string;
        sid?: number;
    }, headers?: any): Promise<void> {
        return $request.post({
            url: '/v1/chat/clear',
            params,
            headers
        }, { apiPrefix: '' })
    },

    /**
     * 发布验证
     *
     * @param {any} headers 请求头信息
     * @returns {Promise<ChatPublishVerfiyResponse>}
     * @author zero
     */
    verify(headers: any): Promise<any> {
        return $request.post<any>({
            url: '/v1/publish/verify',
            headers
        }, {
            apiPrefix: '',
            isTransformResponse: false
        })
    }
}

export default chatDialogApi
